class Tour < ActiveRecord::Base
  validates_presence_of :name, :message => "请输入线路名称"
  validates_uniqueness_of :name, :message => "已经存在同名线路"
  validates_presence_of :tour_category => "请选择线路分类"
  # 对关联的 Picture(Attachment) 对象进行验证，Attachment 对象的验证失败原因无法出现在 Tour 对象的
  # 错误列表里，见 Agile Web Development with Rails, 2nd Edition P364
  # 只有 Tour 对象有对应的 Picture 对象时才进行验证
  validates_associated :picture, :message => "请上传图片文件", :unless => Proc.new { |tour| tour.picture.nil? } 
  
  belongs_to :tour_category
  has_one :picture, :class_name => "Attachment", :as => :entity, :dependent => :destroy

  
end
